package com.huang.core.helper

import android.os.Environment
import com.huang.core.provider.AppProvider
import com.blankj.utilcode.util.CleanUtils
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.FileUtils
import com.bumptech.glide.Glide

/**
 * Created by Android on 2018/10/26.
 */
class CacheClearHelper {
    @Throws(Exception::class)
    fun getTotalCacheSize(): String {
        var length = FileUtils.getLength(Environment.MEDIA_MOUNTED)
        length += FileUtils.getLength(AppProvider.getInstance().cacheDir)
        if (length > 0) return ConvertUtils.byte2FitMemorySize(length)
        return ""
    }

    /**
     * 清除所有缓存
     *   请创建子线程运行
     * */
    fun clearAllCache() {
        CleanUtils.cleanExternalCache()
        CleanUtils.cleanInternalCache()
        Glide.get(AppProvider.getInstance()).clearDiskCache()
    }
}